﻿using Common.IOC;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Config
{
    public class Configs
    {

        private readonly static IConfiguration _configuration;
        static Configs()
        {
            _configuration = IoCContainer.Resolve<IConfiguration>();
        }
        /// <summary>
        /// 根据key获取配置内容
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static IConfigurationSection GetSection(string key)
        {
            return _configuration.GetSection(key);
        }
        /// <summary>
        /// 根据section和key获取配置内容
        /// </summary>
        /// <param name="setion"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetConfigurationValue(string setion, string key)
        {
            return GetSection(setion)?[key];
        }
        /// <summary>
        /// 根据Key获取数据库连接字符串
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetConnectionString(string key)
        {
            return _configuration.GetConnectionString(key);
        }
    }
}
